var utilSevice = require('../../utilService.js')
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    moreData: {
      type: Array,
      value: []
    },
    goodsType: {
      type: Number,
      value: 0
    },
    hasNextPage: {
      type: Boolean,
      value: false
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    moreListData: [],
    startPage: 0,
    isLoading:true
  },

  ready: function () {
    this.startPage = 0
    this.request()
  },
  /**
   * 组件的方法列表
   */
  methods: {
    /**
 * 更多商品加载更多
 */
    reachBottom() {
      if (this.data.hasNextPage == true) {
        this.request()
      }
    },
    /**
     * 取保存的商品名 查询更多商品使用，使返回数据定位更加精准
     */
    getProductName(success) {
      try {
        var value = wx.getStorageSync('products')
        success(value)
      } catch (e) {
        // Do something when catch error
      }
    },
    request: function () {
      this.isLoading = true
      var that = this
      var param = ""
      this.getProductName(function(res){
        var datas = res.split(",");
        param = datas.join("")         
      })
      var params = {
        userId: getApp().globalData.userId,
        goodsType: this.properties.goodsType,
        startPage: this.data.startPage,
        param: param
      }

      utilSevice.getMoreListData(params,
        function (data) {
          that.isLoading = false
          let allData = that.data.moreListData.concat(data.items)
          that.setData({ moreListData: allData, hasNextPage: data.hasNextPage, startPage: data.nextPage, isLoading: false});
        },
        function (error) {
          that.isLoading = false
          wx.showToast({
            title: error.data.message,
            icon: 'none',
            duration: 2000,
          })
        })
    },
  }
})
